<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<jsp:include page="header.jsp" />
<f:view>

	<h:form>
		<h:panelGroup layout="block" styleClass="t">
			<h:panelGroup layout="block" styleClass="b">
				<h:panelGroup layout="block" styleClass="l">
					<h:panelGroup layout="block" styleClass="r">
						<h:panelGroup layout="block" styleClass="bl">
							<h:panelGroup layout="block" styleClass="br">
								<h:panelGroup layout="block" styleClass="tl">
									<h:panelGroup layout="block" styleClass="tr">

										<h:panelGrid columns="1" cellspacing="0" cellpadding="5"
											border="0" styleClass="formtable" captionClass="mainTitle">
											<f:facet name="caption">
												<h:panelGroup>
													<h:panelGroup layout="block">
														<h:outputText value="Create supplier"
															rendered="#{supplierEditBean.supplierId == 0}"></h:outputText>
														<h:outputText value="Edit supplier"
															rendered="#{supplierEditBean.supplierId > 0}"></h:outputText>
													</h:panelGroup>
												</h:panelGroup>
											</f:facet>
											<h:panelGroup>
												<b><h:outputText value="Name:"></h:outputText> </b>
												<h:message for="supplierName" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="supplierName"
													value="#{supplierEditBean.supplier.name}" required="true"
													requiredMessage="Name is required" label="Name"
													styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>


											<h:panelGroup>
												<b><h:outputText value="Address:"></h:outputText>
												</b>
												<h:message for="supplierAddress" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="supplierAddress"
													value="#{supplierEditBean.supplier.address}"
													required="true" requiredMessage="Address is required"
													label="Address" styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>


											<h:panelGroup>
												<b><h:outputText value="Magazines:"></h:outputText></b>
												<h:message for="supplierMagazines" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br/>
													<h:selectManyCheckbox id="supplierMagazines" immediate="true"
												value="#{supplierEditBean.magazineItems}" label="Magazines"
												styleClass="coolinp" layout="pageDirection">
												<f:selectItems value="#{magazineBean.magazineItems}" />
											</h:selectManyCheckbox>
											</h:panelGroup>

											

											<h:panelGroup>												
												<h:inputHidden  
													value="#{supplierEditBean.supplierId}" />
												<input type="hidden" value="<%= request.getParameter("supplierId")!=null ? Integer.parseInt(request.getParameter("supplierId")) : 0 %>" name="supplierId"/>
												<h:commandButton action="#{supplierEditBean.saveSupplier}"
													value="Save" accesskey="s" styleClass="frmbutton">
												</h:commandButton>
												<h:outputText value="&nbsp;" escape="false"></h:outputText>
												<h:commandButton action="#{supplierEditBean.cancel}"
													value="Cancel" accesskey="c" immediate="true"
													styleClass="frmbutton">
												</h:commandButton>
												<h:outputText value="&nbsp;" escape="false"></h:outputText>
												<h:commandButton action="#{supplierEditBean.deleteSupplier}"
													value="Delete" accesskey="d" immediate="true"
													styleClass="frmbutton"
													rendered="#{supplierEditBean.supplierId > 0}" onclick="if(!confirm('Are you sure you want to delete this supplier?'))return false;">
												</h:commandButton>
											</h:panelGroup>
										</h:panelGrid>


									</h:panelGroup>
								</h:panelGroup>
							</h:panelGroup>
						</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>
			</h:panelGroup>
		</h:panelGroup>
	</h:form>
</f:view>

<jsp:include page="footer.jsp" />
